package com.kid.lab;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kid.mybatis.domain.Account;

@Controller
@RequestMapping("/lab")
public class LabController {
	
	@RequestMapping("/jsonIn")
	@ResponseBody
	public void jsonIn(
			@RequestBody Family fs,
			HttpSession httpSession) {
		//System.out.println(fs.get(0).getDogs().get("Dog2").getName());
		//System.out.println(fs[0].getDogs().get("Dog2").getName());
		System.out.println(fs.getDogs().get("Dog2").getName());
	}
	
	@RequestMapping("/jsonOut")
	@ResponseBody
	public List<Family> jsonOut(
			//@RequestBody Account account,
			//@RequestBody Account account,
			HttpSession httpSession) {
		
		List<Family> fs =new ArrayList<Family>();
		Family f = new Family();
		fs.add(f);
		
		Person p = new Person();
		p.setAge(30);
		p.setName("Father1");
		f.setFather(p);
		
		p = new Person();
		p.setAge(28);
		p.setName("Mother1");
		f.setMother(p);
		
		p = new Person();
		p.setAge(6);
		p.setName("Child1");
		f.getChildren().add(p);
		
		p = new Person();
		p.setAge(6);
		p.setName("Child2");
		f.getChildren().add(p);
		
		Dog d = new Dog();
		d.setAge(3);
		d.setColor("yellow");
		d.setName("Dog1");
		f.getDogs().put(d.getName(), d);
		
		d = new Dog();
		d.setAge(5);
		d.setColor("Black");
		d.setName("Dog2");
		f.getDogs().put(d.getName(), d);
		
		return fs;
	}
}
